package com.example.learndevice.adapter

import android.content.Context
import android.hardware.Camera
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.learndevice.R
import com.example.learndevice.bean.CameraInfo

/**
 *
 * @Author： LJH
 * @Time： 2022/7/5
 * @description：
 */
class CameraAdapter(context:Context,cameraList:ArrayList<CameraInfo>):RecyclerView.Adapter<CameraAdapter.ViewHolder>() {
    private var mCameraList:ArrayList<CameraInfo> = cameraList
    private var mContext: Context = context

    inner class ViewHolder(view:View):RecyclerView.ViewHolder(view){
        val tvCameraType = view.findViewById<TextView>(R.id.tv_camera_type)
        val tvFlashMode = view.findViewById<TextView>(R.id.tv_flash_mode)
        val tvFocusMode = view.findViewById<TextView>(R.id.tv_focus_mode)
        val tvSceneMode = view.findViewById<TextView>(R.id.tv_scene_mode)
        val tvColorEffect = view.findViewById<TextView>(R.id.tv_color_effect)
        val tvWhiteBalance = view.findViewById<TextView>(R.id.tv_white_balance)
        val tvMaxZoom = view.findViewById<TextView>(R.id.tv_max_zoom)
        val tvZoom = view.findViewById<TextView>(R.id.tv_zoom)
        val tvResolution = view.findViewById<TextView>(R.id.tv_resolution)
        val tvResolutionList = view.findViewById<TextView>(R.id.tv_resolution_list)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_camera,parent,false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val cameraInfo = mCameraList[position]
        holder.tvCameraType.text = cameraInfo.cameraType
        holder.tvFlashMode.text = cameraInfo.flashMode
        holder.tvFocusMode.text = cameraInfo.focusMode
        holder.tvSceneMode.text = cameraInfo.sceneMode
        holder.tvColorEffect.text = cameraInfo.colorEffect
        holder.tvWhiteBalance.text = cameraInfo.whiteBalance
        holder.tvMaxZoom.text = "${cameraInfo.maxZoom}"
        holder.tvZoom.text = "${cameraInfo.zoom}"
        //holder.tv_resolution_list.setVisibility(View.GONE);
        var desc = ""
        for (i in cameraInfo.resolutionList.indices){
            val size:Camera.Size = cameraInfo.resolutionList[i]
            desc = "$desc 分辨率${i+1}为：宽${size.width}高${size.height}\n"
        }
        holder.tvResolutionList.text = desc
        holder.tvResolution.setOnClickListener {
            var visibility = holder.tvResolutionList.visibility
            if (visibility == View.GONE){
                holder.tvResolution.text = "收起"
                holder.tvResolutionList.visibility = View.VISIBLE
            }else{
                holder.tvResolution.text = "展示"
                holder.tvResolutionList.visibility = View.GONE
            }
        }
    }

    override fun getItemCount(): Int = mCameraList.size

}